function Security_Code() {
	var buffer = new StringBuffer();
	var date=new Date();
	buffer.append('<div id="find" class="finds"><div class="searchinput ui-border-radius"><input id="keyword" class="bordersolid" type="text" value="" onblur="Show_Search()" onkeyup="Security_Search();"/></div><div id="searchicon" class="searchicon"><img src="img/jing.jpg"/></div><div id="searchicons" class="searchicons"><img src="img/jings.jpg"/></div><div class="screen"><button id="screen" class="ui-border-radius" year="'+date.getFullYear()+'" month="'+(date.getMonth()+1)+'">'+(date.getMonth()+1)+'月</button></div></div>');
	buffer.append('<div class="horizen border-bottom"></div>');
	return buffer.toString();
};
function Security_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		var lightgray="";
		if(!info.IsSecurity)
		{
			lightgray="lightgray";
		}
		buffer.append('<div class="matelist border-bottom '+lightgray+'" id="'+info.ID+'" salary="'+info.BSalary+'" security="'+info.Security+'" issecurity="'+info.IsSecurity+'" basicsecurity="'+info.BasicSecurity+'"><div class="matename"><div class="realname">'+info.RealName+'</div><div class="birthplace ispaymoney">'+(info.IsSecurity?(info.IsPayMoney?"<font class='greens'>已缴</font>":"<font class='reds'>未缴</font>"):"停保")+'</div></div><div class="mateinfo">'+(info.IsSecurity?info.Security:"")+'</div></div>');
	});
	return buffer.toString();
};
function Init_Security_Code()
{
	get("find").addEventListener("tap",function(){
		$("#searchicon").hide();
	    $("#searchicons").show();
	    $("#keyword").attr("placeholder","姓名、用户名、电话");
		if($("keyword").val()!="")
		{
			//WorkMate_Search();
		}
	});
	get("screen").addEventListener("tap",function(){
		Show_Month(function(year,month){
			
			$("#screen").attr("year",year).attr("month",month).html(month+"月");
			Security_Search();
		});
		stopEvent();
	});
};
function Security_Search(){
	pageindex=1;
	$("#divmsg1").attr("pageindex","0");
	Receive_Security(1);
};
function Receive_Security(pageindex)
{
	var data = {};
			data.act = "Find_UserSecurity";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.keyword = $("#keyword").val();
			data.year=RUndefined($("#screen").attr("year"));
			data.month=RUndefined($("#screen").attr("month"));
    		data.sign=GetSign(data.act);
			mui.getJSON(index_domain, data, function(json) {
				if(json.data.user.length>0)
				{
					if(pageindex==1)
					{
						$("#contentlist1").html(Security_Data(json.data.user));
					}else{
						$("#contentlist1").append(Security_Data(json.data.user));
					}
					setTimeout(function(){
						Init_Security();
						myScroll1.refresh();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					if(json.data.user.length!=data.pagesize)
					{
						$("#loading1").html("");
					}else{
						$("#loading1").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					
					if(pageindex==1)
					{
						$("#contentlist1").html("");
						$("#loading1").html("主人，没有找到您需要的数据"); 
					}
					else
					{
						$("#loading1").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#divmsg1").attr("pageindex"))+1;
         		$("#divmsg1").attr("pageindex",pageindex);
			});
};
function Init_Security()
{
	mui("#contentlist1").off("tap",".matelist");
	mui("#contentlist1").on("tap",".matelist",function(){
		obj=$(this);
		OpenWindow(2,obj.find(".realname").html()+"的社保记录","",function(){
			
		});
		$("#divmsg2").append('<div class="smsandphone border-top"><button id="securityset" class="button11 blue">设置</button><button id="securitycharge" class="button22 blue">缴费</button></div>');
		Init_SecurityDetail();
		SecurityDetail_Data();
	});
	
};

function Init_SecurityDetail(){
	get("securityset").addEventListener("tap",function(){
			OpenWindow(3,"设置"+obj.find(".realname").html()+"的社保项","保存",function(){
				Save_SecuritySet();
			});
			$("#contentlist3").html(SecuritySet_Code());
			get("tools_issecurity").addEventListener("tap",function(){
				var buttons=[{title:"在保"},{title:"停保"}];
				plus.nativeUI.actionSheet( {title:"选择社保状态",cancel:"取消",buttons:buttons}, function(e){
					if(e.index>0){
						$("#txt_issecurity").attr("val",e.index==1?"true":"false").val(buttons[e.index-1].title);
					}
				});
			});
	});
	get("securitycharge").addEventListener("tap",function(){
			if(obj.find(".ispaymoney font").html()=="已缴")
			{
				plus.nativeUI.alert(obj.find(".realname").html()+$("#screen").attr("year")+"年"+$("#screen").attr("month")+"月社保已缴");
				return;
			}
			OpenWindow(3,"缴纳社保","保存",function(){
				Save_Security();
			});
			$("#contentlist3").html(SecurityAdd_Code(0,obj.find(".realname").html(),obj.attr("basicsecurity")));
			Init_SecurityAdd();
			Cal_Security();
	});
};
function Save_SecuritySet()
{
		var data = {};
		data.act = "Save_SecuritySet";
		data.uid=obj.attr("id");
		data.issecurity=$("#txt_issecurity").attr("val");
		data.security=CRM.ListValue($(".userlist input:checked"))+"";
		data.basicsecurity=$("#txt_basicsecurity").val();
        data.userid=userid;
		data.comid=comid;
        data.source = source;
        data.version = version;
        data.sign=GetSign(data.act);
        plus.nativeUI.showWaiting( "正在保存..." );
	    CloseWaiting(10000);
        mui.getJSON(index_domain, data, function (json) {
        	plus.nativeUI.closeWaiting();
        	plus.nativeUI.toast(json.msg);
            if (json.state) {
                CloseWindow();
                Security_Search();
                obj.attr("basicsecurity",data.basicsecurity);
                obj.attr("security",data.security.replace("1", "养老").replace("2", "医疗").replace("3", "失业").replace("4", "工伤").replace("5", "生育").replace("6", "公积金").ReplaceAll(",","+"));
            }
        });
};
function Save_SecurityPercent()
{
		var data = {};
		data.act = "Save_SecurityPercent";
		data.securitypercent=$("#txt_ayanglao").val()+"-"+$("#txt_byanglao").val()+","+$("#txt_ayiliao").val()+"-"+$("#txt_byiliao").val()+","+$("#txt_ashiye").val()+"-"+$("#txt_bshiye").val()+","+$("#txt_agongshang").val()+"-"+$("#txt_bgongshang").val()+","+$("#txt_ashengyu").val()+"-"+$("#txt_bshengyu").val()+","+$("#txt_agongjijin").val()+"-"+$("#txt_bgongjijin").val();
        data.userid=userid;
		data.comid=comid;
        data.source = source;
        data.version = version;
        data.sign=GetSign(data.act);
        plus.nativeUI.showWaiting( "正在保存..." );
	    CloseWaiting(10000);
        mui.getJSON(index_domain, data, function (json) {
        	plus.nativeUI.closeWaiting();
        	plus.nativeUI.toast(json.msg);
            if (json.state) {
                CloseWindow();
                User.SecurityPercent=data.securitypercent;
                plus.storage.setItem("crm_user",JSON.stringify(User));
            }
        });
};
function SecuritySet_Code(){
	var security=obj.attr("security");
	var issecurity=obj.attr("issecurity");
	var buffer = new StringBuffer();
	buffer.append('<div class="userlist">');
	buffer.append('<div id="tools_issecurity" class="crmsheet border-bottom"><div class="ctitle"><div class="cname" style="padding-left:1px;">社保状态</div></div><div class="ctext"><input id="txt_issecurity" type="text" placeholder="" value="'+(issecurity=="true"?"在保":"停保")+'" val="'+issecurity+'" readonly="readonly" style="text-align:right;"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">缴费基数</div></div><div class="ctext" style="width:70%;"><input id="txt_basicsecurity" type="tel" placeholder="输入缴费基数" value="'+obj.attr("basicsecurity").toFixed(2)+'" style="text-align:right; padding-right:15px;"/></div></div>');
	buffer.append('<div class="ulist mui-checkbox border-bottom" style="height:37px;"><div class="realname">养老保险</div><div class="checkbox"><input name="checkbox1" value="1" type="checkbox" '+(security.indexOf("养老")>-1?"checked":"")+'></div></div>');
	buffer.append('<div class="ulist mui-checkbox border-bottom" style="height:37px;"><div class="realname">医疗保险</div><div class="checkbox"><input name="checkbox1" value="2" type="checkbox" '+(security.indexOf("医疗")>-1?"checked":"")+'></div></div>');
	buffer.append('<div class="ulist mui-checkbox border-bottom" style="height:37px;"><div class="realname">失业保险</div><div class="checkbox"><input name="checkbox1" value="3" type="checkbox" '+(security.indexOf("失业")>-1?"checked":"")+'></div></div>');
	buffer.append('<div class="ulist mui-checkbox border-bottom" style="height:37px;"><div class="realname">工伤保险</div><div class="checkbox"><input name="checkbox1" value="4" type="checkbox" '+(security.indexOf("工伤")>-1?"checked":"")+'></div></div>');
	buffer.append('<div class="ulist mui-checkbox border-bottom" style="height:37px;"><div class="realname">生育保险</div><div class="checkbox"><input name="checkbox1" value="5" type="checkbox" '+(security.indexOf("生育")>-1?"checked":"")+'></div></div>');
	buffer.append('<div class="ulist mui-checkbox border-bottom" style="height:37px;"><div class="realname">公积金</div><div class="checkbox"><input name="checkbox1" value="6" type="checkbox" '+(security.indexOf("公积金")>-1?"checked":"")+'></div></div>');
	buffer.append('</div>');
	return buffer.toString();
};

function SecurityPercent_Code(){
	var buffer = new StringBuffer();
	var percent=User.SecurityPercent.split(",");
	var yanglao=RUndefined(percent[0]).split("-");
	var yiliao=RUndefined(percent[1]).split("-");
	var shiye=RUndefined(percent[2]).split("-");
	var gongshang=RUndefined(percent[3]).split("-");
	var shengyu=RUndefined(percent[4]).split("-");
	var gongjijin=RUndefined(percent[5]).split("-");
	buffer.append('<div class="crmsheet border-bottom" style="background-color:#f6f6f5;"><div class="ctitle">保险名称</div><div class="ctitle" style="width:35%;">个人缴纳(%)</div><div class="ctitle" style="width:35%;">公司缴纳(%)</div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">养老保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ayanglao" type="tel" placeholder="输入百分比" value="'+yanglao[0]+'" style="width:45%"/><input id="txt_byanglao" type="tel" placeholder="输入百分比" value="'+RUndefined(yanglao[1])+'" style="width:45%; margin-left:10px;"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">医疗保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ayiliao" type="tel" placeholder="输入百分比" value="'+yiliao[0]+'" style="width:45%"/><input id="txt_byiliao" type="tel" placeholder="输入百分比" value="'+RUndefined(yiliao[1])+'" style="width:45%; margin-left:10px;"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">失业保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ashiye" type="tel" placeholder="输入百分比" value="'+shiye[0]+'" style="width:45%"/><input id="txt_bshiye" type="tel" placeholder="输入百分比" value="'+RUndefined(shiye[1])+'" style="width:45%; margin-left:10px;"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">工伤保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_agongshang" type="tel" placeholder="输入百分比" value="'+gongshang[0]+'" style="width:45%"/><input id="txt_bgongshang" type="tel" placeholder="输入百分比" value="'+RUndefined(gongshang[1])+'" style="width:45%; margin-left:10px;"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">生育保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ashengyu" type="tel" placeholder="输入百分比" value="'+shengyu[0]+'" style="width:45%"/><input id="txt_bshengyu" type="tel" placeholder="输入百分比" value="'+RUndefined(shengyu[1])+'" style="width:45%; margin-left:10px;"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">公积金</div><div class="require">*</div></div><div class="ctext2"><input id="txt_agongjijin" type="tel" placeholder="输入百分比" value="'+gongjijin[0]+'" style="width:45%"/><input id="txt_bgongjijin" type="tel" placeholder="输入百分比" value="'+RUndefined(gongjijin[1])+'" style="width:45%; margin-left:10px;"/></div></div>');
	return buffer.toString();
};

function SecurityDetail_Data(){
	
	var data = {};
		data.act = "Find_SecurityDetail";
		data.uid=obj.attr("id");
		data.source=source;
		data.userid=userid;
		data.comid=comid;
		data.sign=GetSign(data.act);
		mui.getJSON(index_domain, data, function (json) {
			var str="";
		    if (json.state) {
		    	if(json.data.list.length>0)
		    	{
			    	$.each(json.data.list,function(i,info){
			    		str+='<div class="matelist border-bottom" id="'+info.ID+'" ayanglao="'+info.AYangLao+'" ayiliao="'+info.AYiLiao+'" ashiye="'+info.AShiYe+'" agongshang="'+info.AGongShang+'" ashengyu="'+info.AShengYu+'" agongjijin="'+info.AGongJiJin+'" byanglao="'+info.BYangLao+'" byiliao="'+info.BYiLiao+'" bshiye="'+info.BShiYe+'" bgongshang="'+info.BGongShang+'" bshengyu="'+info.BShengYu+'" bgongjijin="'+info.BGongJiJin+'" aallmoney="'+info.AAllMoney+'" ballmoney="'+info.BAllMoney+'" year="'+info.Year+'" month="'+info.Month+'"><div class="matename"><div class="realname">'+obj.find(".realname").html()+'</div><div class="birthplace"><font>'+info.Month+'月</font></div></div><div class="mateinfo"><div class="sex">个人缴纳：'+info.AAllMoney.toFixed(2)+'</div><div class="joindate">公司缴纳：'+info.BAllMoney.toFixed(2)+'</div></div></div>';
			    	});
			    	$("#contentlist2").html(str);
		    	}else
		    	{
		    		$("#contentlist2").html('<div id="loading2" class="loading">主人，没有找到相关合同记录</div>');
		    	}
		    }
		    if($("#contentlist2 .matelist").length>0){
			    $("#contentlist2 .matelist:first")[0].addEventListener("tap",function(){
			    	OpenWindow(3,"修改社保","保存",function(){
						Save_Security();
					});
					$("#contentlist3").html(SecurityUpdate_Code($(this).attr("id"),obj.find(".realname").html(),obj.attr("basicsecurity"),$(this)));
					Init_SecurityAdd();
					Cal_Security();
			    });
		    }
		});
		
};
function SecurityAdd_Code(id,realname,basicsecurity){
	var security=obj.attr("security");
	var percent=User.SecurityPercent.split(",");
	var yanglao=RUndefined(percent[0]).split("-");
	var yiliao=RUndefined(percent[1]).split("-");
	var shiye=RUndefined(percent[2]).split("-");
	var gongshang=RUndefined(percent[3]).split("-");
	var shengyu=RUndefined(percent[4]).split("-");
	var gongjijin=RUndefined(percent[5]).split("-");
	var buffer = new StringBuffer();
	buffer.append('<div id="securityid" val="'+id+'" class="crmsheet border-bottom"><div class="ctitle"><div class="cname">员工姓名</div></div><div class="ctext"><input type="text" readonly="readonly" value="'+realname+'" /></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">缴费基数</div></div><div class="ctext"><input type="text" readonly="readonly" value="'+basicsecurity.toFixed(2)+'" /></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">缴费年月</div></div><div class="ctext"><input type="text" readonly="readonly" value="'+$("#screen").attr("year")+"年"+$("#screen").attr("month")+'月" /></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom" style="background-color:#f6f6f5;"><div class="ctitle">保险名称</div><div class="ctitle" style="width:35%;">个人缴纳</div><div class="ctitle">公司缴纳</div></div>');
	if(security.indexOf("养老")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">养老保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ayanglao" type="tel" placeholder="输入金额" value="'+(basicsecurity*yanglao[0]/100).toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_byanglao" type="tel" placeholder="输入金额" value="'+(basicsecurity*yanglao[1]/100).toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("医疗")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">医疗保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ayiliao" type="tel" placeholder="输入金额" value="'+(basicsecurity*yiliao[0]/100).toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_byiliao" type="tel" placeholder="输入金额" value="'+(basicsecurity*yiliao[1]/100).toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("失业")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">失业保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ashiye" type="tel" placeholder="输入金额" value="'+(basicsecurity*shiye[0]/100).toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_bshiye" type="tel" placeholder="输入金额" value="'+(basicsecurity*shiye[1]/100).toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("工伤")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">工伤保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_agongshang" type="tel" placeholder="输入金额" value="'+(basicsecurity*gongshang[0]/100).toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_bgongshang" type="tel" placeholder="输入金额" value="'+(basicsecurity*gongshang[1]/100).toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("生育")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">生育保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ashengyu" type="tel" placeholder="输入金额" value="'+(basicsecurity*shengyu[0]/100).toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_bshengyu" type="tel" placeholder="输入金额" value="'+(basicsecurity*shengyu[1]/100).toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("公积金")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">公积金</div><div class="require">*</div></div><div class="ctext2"><input id="txt_agongjijin" type="tel" placeholder="输入金额" value="'+(basicsecurity*gongjijin[0]/100).toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_bgongjijin" type="tel" placeholder="输入金额" value="'+(basicsecurity*gongjijin[1]/100).toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	buffer.append('<div class="crmsheet" style="height:35px;"><div class="ctitle"><div class="cname">合计</div></div><div class="ctext2"><input id="txt_aallmoney" type="text" readonly="readonly" value="0.00" style="width:45%"/><input id="txt_ballmoney" type="text" readonly="readonly" value="0.00" style="width:45%; margin-left:10px;"/></div></div>');
	buffer.append('<div class="crmsheet" style="height:30px;"><div class="ctitle"><div class="cname">总计</div></div><div class="ctext"><input id="txt_allmoney" type="text" readonly="readonly" value="0.00"/></div></div>');
	if(id!=0){
	buffer.append('<div id="deletesheet" class="deletesheet" style="margin-top:20px;"><div class="name" style="width:100%; text-align:center;">删除该社保</div></div>');
	}
	return buffer.toString();
};

function SecurityUpdate_Code(id,realname,basicsecurity,o){
	var security=obj.attr("security");
	var buffer = new StringBuffer();
	buffer.append('<div id="securityid" val="'+id+'" class="crmsheet border-bottom"><div class="ctitle"><div class="cname">员工姓名</div></div><div class="ctext"><input type="text" readonly="readonly" value="'+realname+'" /></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">缴费基数</div></div><div class="ctext"><input type="text" readonly="readonly" value="'+basicsecurity.toFixed(2)+'" /></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">缴费年月</div></div><div class="ctext"><input type="text" readonly="readonly" value="'+o.attr("year")+"年"+o.attr("month")+'月" /></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom" style="background-color:#f6f6f5;"><div class="ctitle">保险名称</div><div class="ctitle" style="width:35%;">个人缴纳</div><div class="ctitle">公司缴纳</div></div>');
	if(security.indexOf("养老")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">养老保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ayanglao" type="text" placeholder="输入金额" value="'+o.attr("ayanglao").toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_byanglao" type="text" placeholder="输入金额" value="'+o.attr("byanglao").toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("医疗")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">医疗保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ayiliao" type="text" placeholder="输入金额" value="'+o.attr("ayiliao").toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_byiliao" type="text" placeholder="输入金额" value="'+o.attr("byiliao").toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("失业")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">失业保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ashiye" type="text" placeholder="输入金额" value="'+o.attr("ashiye").toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_bshiye" type="text" placeholder="输入金额" value="'+o.attr("bshiye").toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("工伤")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">工伤保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_agongshang" type="text" placeholder="输入金额" value="'+o.attr("agongshang").toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_bgongshang" type="text" placeholder="输入金额" value="'+o.attr("bgongshang").toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("生育")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">生育保险</div><div class="require">*</div></div><div class="ctext2"><input id="txt_ashengyu" type="text" placeholder="输入金额" value="'+o.attr("ashengyu").toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_bshengyu" type="text" placeholder="输入金额" value="'+o.attr("bshengyu").toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	if(security.indexOf("公积金")>-1){
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">公积金</div><div class="require">*</div></div><div class="ctext2"><input id="txt_agongjijin" type="text" placeholder="输入金额" value="'+o.attr("agongjijin").toFixed(2)+'" style="width:45%" onkeyup="Cal_Security()"/><input id="txt_bgongjijin" type="text" placeholder="输入金额" value="'+o.attr("bgongjijin").toFixed(2)+'" style="width:45%; margin-left:10px;" onkeyup="Cal_Security()"/></div></div>');
	}
	buffer.append('<div class="crmsheet" style="height:35px;"><div class="ctitle"><div class="cname">合计</div></div><div class="ctext2"><input id="txt_aallmoney" type="text" readonly="readonly" value="0.00" style="width:45%"/><input id="txt_ballmoney" type="text" readonly="readonly" value="0.00" style="width:45%; margin-left:10px;"/></div></div>');
	buffer.append('<div class="crmsheet" style="height:30px;"><div class="ctitle"><div class="cname">总计</div></div><div class="ctext"><input id="txt_allmoney" type="text" readonly="readonly" value="0.00"/></div></div>');
	if(id!=0){
	buffer.append('<div id="deletesheet" class="deletesheet" style="margin-top:20px;"><div class="name" style="width:100%; text-align:center;">删除该社保</div></div>');
	}
	return buffer.toString();
};


function Cal_Security(){
	var aallmoney=0,ballmoney=0;
	if($("#txt_ayanglao").length>0){aallmoney+=parseFloat($("#txt_ayanglao").val());ballmoney+=parseFloat($("#txt_byanglao").val());}
	if($("#txt_ayiliao").length>0){aallmoney+=parseFloat($("#txt_ayiliao").val());ballmoney+=parseFloat($("#txt_byiliao").val());}
	if($("#txt_ashiye").length>0){aallmoney+=parseFloat($("#txt_ashiye").val());ballmoney+=parseFloat($("#txt_bshiye").val());}
	if($("#txt_agongshang").length>0){aallmoney+=parseFloat($("#txt_agongshang").val());ballmoney+=parseFloat($("#txt_bgongshang").val());}
	if($("#txt_ashengyu").length>0){aallmoney+=parseFloat($("#txt_ashengyu").val());ballmoney+=parseFloat($("#txt_bshengyu").val());}
	if($("#txt_agongjijin").length>0){aallmoney+=parseFloat($("#txt_agongjijin").val());ballmoney+=parseFloat($("#txt_bgongjijin").val());}
	$("#txt_aallmoney").val(aallmoney.toFixed(2));
	$("#txt_ballmoney").val(ballmoney.toFixed(2));
	$("#txt_allmoney").val((aallmoney+ballmoney).toFixed(2));
};


function Init_SecurityAdd(){
	if($("#securityid").attr("val")!="0")
		{
			get("deletesheet").addEventListener("tap",function(){
		        	plus.nativeUI.confirm("确定要删除吗？", function(event){
						if(event.index==1)
						{
							var data = {};
						    data.act = "Delete_Security";
						    data.ids = $("#securityid").attr("val");
						    data.uid=obj.attr("id");
						    data.userid=userid;
							data.comid=comid;
							data.source=source;
							data.sign=GetSign(data.act);
						    mui.getJSON(index_domain, data, function(json) {
								if(json.state)
								{
									$("#contentlist2 .matelist:last").remove();
									
									CloseWindow();
									plus.nativeUI.toast(json.msg);
									Security_Search();
									SecurityDetail_Data();
								}else
								{
									plus.nativeUI.alert(json.msg);
								}
								
						    });	
						}
					},"提示", ["取消","确认"]);
				
			});
		}
	
};


function Save_Security() {
        var data = {};
        data.id = $("#securityid").attr("val");
		data.act = "Save_Security";
		data.uid=obj.attr("id");
		data.security=obj.attr("security").replace("养老", "1").replace("医疗", "2").replace("失业", "3").replace("工伤", "4").replace("生育", "5").replace("公积金", "6").replace("+",",").replace("+",",").replace("+",",").replace("+",",").replace("+",",");
		data.ayanglao=$("#txt_ayanglao").val();
		data.ayiliao=$("#txt_ayiliao").val();
		data.ashiye=$("#txt_ashiye").val();
		data.agongshang=$("#txt_agongshang").val();
		data.ashengyu=$("#txt_ashengyu").val();
		data.agongjijin=$("#txt_agongjijin").val();
		data.aallmoney=$("#txt_aallmoney").val();
		data.byanglao=$("#txt_byanglao").val();
		data.byiliao=$("#txt_byiliao").val();
		data.bshiye=$("#txt_bshiye").val();
		data.bgongshang=$("#txt_bgongshang").val();
		data.bshengyu=$("#txt_bshengyu").val();
		data.bgongjijin=$("#txt_bgongjijin").val();
		data.ballmoney=$("#txt_ballmoney").val();
		data.year=$("#screen").attr("year");
		data.month=$("#screen").attr("month");
        data.userid=userid;
		data.comid=comid;
        data.source = source;
        data.version = version;
        data.sign=GetSign(data.act);
        plus.nativeUI.showWaiting( "正在执行..." );
	    CloseWaiting(10000);
        mui.getJSON(index_domain, data, function (json) {
        	plus.nativeUI.closeWaiting();
        	plus.nativeUI.toast(json.msg);
            if (json.state) {
                CloseWindow(); 
                obj.find(".ispaymoney font").html("已缴");
                SecurityDetail_Data();
                Security_Search();
            }
        });
};
